//
//  STCoinExplainViewModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2019/1/18.
//  Copyright © 2019年 HCreater. All rights reserved.
//

#import "STCoinExplainViewModel.h"

@interface STCoinExplainViewModel ()

@property (nonatomic, readwrite, strong) RACCommand* requestDataCmd;

@end

@implementation STCoinExplainViewModel

- (void)initialize
{
    [super initialize];
    
    @weakify(self);
    
    self.requestDataCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input)
    {
        @strongify(self);
        
        return [self _requestExplain];
    }];
}

- (RACSignal*)_requestExplain
{
    @weakify(self);
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber)
    {
        @strongify(self);
        
        @weakify(self);
        [[AFNetWorkUtils racPOSTWthURL:url_interface_getmessagedetail params:interface_param_getmessagedetail()] subscribeNext:^(id x)
         {
             @strongify(self);
             
             /// 转化数据
             @weakify(self);
             
             self.strExplain = x[@"content"];
             
             [subscriber sendNext:nil];
             [subscriber sendCompleted];
             
         } error:^(NSError *error)
         {
             //错误处理
             
             NSString* strError = [error.userInfo[customErrorInfoKey] isNotBlank] ? error.userInfo[customErrorInfoKey] : @"获取用户生态币说明失败";
             [subscriber sendError:[NSError errorWithDomain:SUCommandErrorDomain code:SUCommandErrorCode userInfo:@{SUCommandErrorUserInfoKey:strError}]];
             [subscriber sendCompleted];
         }];
        
        return nil;
    }];
}

@end
